package com.yowasa.xiuxian.engine.battle.enemy.strategy;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.engine.battle.strategy.BaseSpellStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.BuffContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.exception.HandlerException;
import com.yowasa.xiuxian.service.helper.BattleHelper;
import com.yowasa.xiuxian.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.*;

@BS(name = "女士")
@Order(1006)
@Component
public class NvShi extends BaseSpellStrategy {
    @Autowired
    private BattleHelper battleHelper;

    @Override
    public ElementEnum getElement() {
        return null;
    }

    private static Map<String, List<String>> firstMap = new HashMap<>();
    private static Map<String, List<String>> secondMap = new HashMap<>();
    private static Map<String, List<String>> thirdMap = new HashMap<>();
    {
        firstMap.put("冰", Arrays.asList("霜华绽放"));
        firstMap.put("火", Arrays.asList("烈焰焚烬"));

        secondMap.put("冰", Arrays.asList("至冬恩典","凝血霜矛"));
        secondMap.put("火", Arrays.asList("流云天照","炎染之舞"));

        thirdMap.put("冰", Arrays.asList("悲叹冰河","哀绪冰雹","冰葬之轮"));
        thirdMap.put("火", Arrays.asList("妄念灼浪","红莲之蝶","烬灭之鞭"));
    }


    @Override
    public void action(UserBattleContent first, UserBattleContent second, BattleContent content) {
        BuffContent buff = second.getBuff().get("妨害");
        if (buff == null) {
            BuffContent buffContent = new BuffContent();
            buffContent.setDuration(20);
            buffContent.setNum(1);
            buffContent.setPositive(false);
            second.getBuff().put("妨害", buffContent);
        }else {
            buff.setDuration(20);
            int num=buff.getNum() + 1;
            buff.setNum(num);
        }

        Map<String, Object> flag = first.getFlag();
        String name = MapUtil.getStr(flag, "女士");
        if(StrUtil.isBlank(name)){
            name = "冰";
        }
        String desc;
        Double v ;
        double random = Math.random();

        if(random < 0.2){
            desc = RandomUtil.choice(firstMap.get(name));
            v = 2.7;
        }else if(random <0.5){
            desc = RandomUtil.choice(secondMap.get(name));
            v = 2.1;
        }else {
            desc = RandomUtil.choice(thirdMap.get(name));
            v = 1.7;
        }
        int orgAtk = first.getBattleInfo().getSpell();
        int def = second.getBattleInfo().getRes();
        int dmg = (int) (battleHelper.calSpell(orgAtk, def) * v);
        battleHelper.autoAction(this, first, second, content, dmg, desc);
    }

    @Override
    public void limit(UserBO user) {
        throw new HandlerException("无法学习妖兽的攻击手段");
    }

    @Override
    public String limitDesc() {
        return "无";
    }

    @Override
    public String desc() {
        return  "瞳仁中倒映着破晓的赤红，她最后展开烈焰之翼向黎明飞去。\n" +
                "「但那并不是曙光，亲爱的罗莎琳。那是焚尽一切的火海。」\n" +
                "在光芒中，一个声音这么对她说。\n" +
                "但这也没什么所谓。因为她心中明白，自己早已被烈火吞没。\n\n" +

                "特性 ： 元素转化、环境伤害、伤害受限 \n" +
                "女士拥有两种元素力，会交替使用两套技能组\n女士完全释放体内的元素力，影响环境，玩家每回合流失10%hp(负面buff，可使用清心咒消除)\n红莲冰茧，女士每次最多只能受到当前生命值5%的最大伤害\n" +
                "掉落物：\n 狱火之蝶,灰烬之心,熔毁之刻";
    }


}
